<template>
  <div class="">
    <el-row>
      <el-col :span="6">
        <h3>当前裁判信息:&nbsp;<el-tag effect="plain">{{referee.type }}</el-tag></h3>
      </el-col>
      <el-col :span="6">
        <h3>当前队伍信息:&nbsp;<el-tag effect="plain">{{scoreData.teamName }}</el-tag></h3>
      </el-col>
      <el-col :span="6">
        <h3>当前评分标准:&nbsp;<el-tag effect="plain">{{ fnName }}</el-tag></h3>
      </el-col>
      <el-col :span="12">
        <h3>当前比赛项目：&nbsp;{{ scoreData.type }}-{{ scoreData.projectName }}-{{ scoreData.groups }}</h3>
      </el-col>
    </el-row>
    <el-card shadow="never" style="margin: 20px 0;">
      <el-row :gutter="10" class="panel-group">
        <el-col :xs="12" :sm="8" :lg="{span: '24-5'}" class="card-panel-col" v-for="(item,index) in refereeList" :key="index" style="margin-bottom: 20px;">
          <el-card shadow="never" :body-style="{ padding: '0px' }">
            <div style="padding-top: 14px;">
              <div class="" style="text-align: center;">
                <div class="" style="margin-bottom: 15px;">{{item.type}}({{ item.name }})</div>
                <!-- <el-input-number v-model="item.score" :precision="2" :step="0.1" :max="10"></el-input-number> -->
                <div v-if="item.type !== '难度裁判'" class="" style="font-size: 30px;padding-top:10px;">{{item.score}}</div>
                <div v-else class="" style="font-size: 30px;padding-top:10px;">{{item.score}}<span style="font-size: 15px;">难度减分{{ item.subScore }}</span></div>
              </div>
              <div class="bottom clearfix" :class="[item.status=='已打分'?'already':'noready']">
                <el-row type="flex" justify="space-around">
                  <el-col v-if="item.status=='申请改分待审批'">
                    <i style="cursor: pointer;" class="el-icon-refresh" @click="agree(item)">重打</i>
                  </el-col>
                  <el-col v-if="item.status=='已打分'">
                    <i style="cursor: pointer;" class="el-icon-bottom">下线</i>
                  </el-col>
                  <el-col>
                    <i style="cursor: pointer;" class="el-icon-edit" @click="change(item)">编辑</i>
                  </el-col>
                </el-row>
              </div>
            </div>
          </el-card>
        </el-col>
        <el-col :xs="12" :sm="8" :lg="{span: '24-5'}" class="card-panel-col">
          <el-card shadow="never" :body-style="{ padding: '0px' }">
            <div style="padding-top: 14px;">
              <div class="" style="text-align: center;">
                <div class="">视线减分</div>
                <div class="" style="font-size: 30px;padding-top:10px;">
                  <el-input-number v-model="sightScore" :precision="2" :step="0.1" :max="100"></el-input-number>
                </div>
              </div>
              <div class="bottom clearfix headreferee">
                <i class="el-icon-edit">编辑</i>
              </div>
            </div>
          </el-card>
        </el-col>
        <el-col v-if="fnName == '竞技健美操'" :xs="12" :sm="8" :lg="{span: '24-5'}" class="card-panel-col">
          <el-card shadow="never" :body-style="{ padding: '0px' }">
            <div style="padding-top: 14px;">
              <div class="" style="text-align: center;">
                <div class="">竞技健美操系数</div>
                <div class="" style="font-size: 30px;padding-top:10px;">
                    <el-select v-model="formula" placeholder="请选择活动区域">
                      <el-option label="竞技健美操2.0" value="竞技健美操2.0"></el-option>
                      <el-option label="竞技健美操1.8" value="竞技健美操1.8"></el-option>
                      <el-option label="竞技健美操1.7" value="竞技健美操1.7"></el-option>
                    </el-select>
                </div>
              </div>
              <div class="bottom clearfix headreferee">
                <i class="el-icon-edit">编辑</i>
              </div>
            </div>
          </el-card>
        </el-col>
      </el-row>
      <el-row :gutter="10" class="panel-group" type="flex">
        <el-col :xs="12" :sm="8" :lg="{span: '24-5'}" class="card-panel-col">
          <el-card shadow="never" :body-style="{ padding: '0px' }">
            <div style="padding-top: 14px;">
              <div class="" style="text-align: center;">
                <div class="">加分</div>
                <div class="" style="font-size: 30px;padding-top:10px;">
                  <el-input-number v-model="addscore" :precision="2" :step="0.1" :max="100"></el-input-number>
                </div>
              </div>
              <div class="bottom clearfix headreferee">
                <i class="el-icon-edit">编辑</i>
              </div>
            </div>
          </el-card>
        </el-col>
        <el-col :xs="12" :sm="8" :lg="{span: '24-5'}" class="card-panel-col">
          <el-card shadow="never" :body-style="{ padding: '0px' }">
            <div style="padding-top: 14px;">
              <div class="" style="text-align: center;">
                <div class="">减分</div>
                <div class="" style="font-size: 30px;padding-top:10px;">
                  <el-input-number v-model="reducescore" :precision="2" :step="0.1" :max="100"></el-input-number>
                </div>
              </div>
              <div class="bottom clearfix headreferee">
                <i class="el-icon-edit">编辑</i>
              </div>
            </div>
          </el-card>
        </el-col>
        <el-col :xs="12" :sm="8" :lg="{span: '24-5'}" class="card-panel-col">
          <el-card shadow="never" :body-style="{ padding: '0px' }">
            <div style="padding-top: 14px;">
              <div class="" style="text-align: center;">
                <div class="" style="margin-bottom: 8px;">分数</div>
                <div class="" style="font-size: 30px;padding-top:10px;">{{this.averageScore}}</div>
              </div>
              <div class="bottom clearfix headreferee1" @click="computedAverage()">
                <i class="el-icon-edit">计算分数</i>
              </div>
            </div>
          </el-card>
        </el-col>
        <el-col :xs="12" :sm="8" :lg="{span: '24-5'}" class="card-panel-col">
          <el-card shadow="never" :body-style="{ padding: '0px' }">
            <div style="padding-top: 14px;">
              <div class="" style="text-align: center;">
                <div class="" style="margin-bottom: 8px;">最终得分</div>
                <div class="" style="font-size: 30px;padding-top:10px;">{{this.computedScore}}</div>
              </div>
              <div class="bottom clearfix headreferee1" @click="computedFinal()">
                <i class="el-icon-edit">计算最终得分</i>
              </div>
            </div>
          </el-card>
        </el-col>
        <el-col :xs="12" :sm="8" :lg="{span: '24-5'}" class="card-panel-col">
          <el-card shadow="never" :body-style="{ padding: '0px' }">
            <div style="padding-top: 14px;">
              <div class="" style="text-align: center;">
                <div class="" style="margin-bottom: 8px;">最终得分</div>
                <div class="" style="font-size: 30px;padding-top:10px;">{{this.computedScore}}</div>
              </div>
              <div class="bottom clearfix headreferee1" @click="submitFinalScore()">
                <i class="el-icon-edit">提交最终得分</i>
              </div>
            </div>
          </el-card>
        </el-col>
          <!-- <el-card shadow="never" :body-style="{ padding: '0px' }">
            <el-row type="flex">
              <el-col>
                <div style="padding-top: 14px;">
                  <div class="" style="text-align: center;">
                    <div class="">总得分</div>
                    <div class="" style="font-size: 80px;padding-top:10px;">{{this.averageScore}}</div>
                  </div>
                </div>
              </el-col>
              <el-col>
                <div style="padding-top: 14px;">
                  <div class="" style="text-align: center;">
                    <div class="">最终得分</div>
                    <div class="" style="font-size: 80px;padding-top:10px;">{{this.computedScore}}</div>
                  </div>
                </div>
              </el-col>
              <el-col>
                <div class="submit-score">
                  <el-button icon="el-icon-upload2" type="primary" @click="computedAverage()">计算平均分</el-button>
                  <el-button icon="el-icon-upload2" type="primary" @click="computedFinal()">计算总分</el-button>
                  <el-button icon="el-icon-upload2" type="success" @click="submitFinalScore()">提交打分</el-button>
                </div>
              </el-col>
            </el-row>
          </el-card> -->
      </el-row>
      <el-row style="margin-top: 30px;">
        <el-col>
          <el-table
            ref="gameTable"
            :data="tableData"
            highlight-current-row
            height="300"
            border
            size="mini"
            style="width: 100%">
            <!-- <el-table-column label="顺序" width="50">
              <template slot-scope="scope">
                {{ scope.$index + 1 }}
              </template>
            </el-table-column> -->
            <el-table-column prop="projectName" label="项目"></el-table-column>
            <el-table-column prop="groups" label="组别"></el-table-column>
            <el-table-column prop="athletes" label="参赛队员" :show-overflow-tooltip="true">
              <template slot-scope="scope">
                {{ scope.row.athletes.map(e => e.name).join(',') }}
              </template>  
            </el-table-column>
            <el-table-column prop="teamName" label="队伍"></el-table-column>
            <el-table-column prop="status" label="状态" width="100">
              <template slot-scope="scope">
                <el-tag
                size="mini"
                  :type="scope.row.status === '已打分' ? 'success' : 'primary'"
                  disable-transitions>{{scope.row.status}}</el-tag>
              </template>
            </el-table-column>
            <el-table-column prop="score" label="分数" width="100"></el-table-column>
          </el-table>
        </el-col>
      </el-row>
    </el-card>
    <el-dialog  :close-on-click-modal="false"
      title="编辑分数"
      :visible.sync="dialogVisible"
      width="30%">
      分数:
      <el-input label="" v-model="input" placeholder="请输入内容"></el-input>
      
      <span v-if="inputBox">难度减分:</span>
      <el-input v-if="inputBox" v-model="input2" placeholder="请输入内容"></el-input>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="editNormalScore">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>
<script>
import { mapState } from 'vuex'
import {getNowData,getAllData,submitscore,agreescore} from '@/api/score'
export default {
  data () {
    return {
      inputBox: false,
      dialogVisible: false,
      input:'',
      input2:'',
      scoreId:'',
      fnName:'健身操舞',
      formula:'健身操舞',
      averageScore:0,
      finalScore:0,
      computedScore:0,
      addscore:0,
      sightScore:0,
      reducescore:0,
      scoreData:{},
      timer:null, //定时器名称
      score:null,
      form:{
        value:null,
      },
      normalscore:{},
      tableData: [],
      refereeList:[
        // {
        //   refereeId: '169364142917657',
        //   competitionId: '169364009900655',
        //   applyProjectId: '169364029354930',
        //   orderId: '169364041855915',
        //   idCard: '150422199803063328',
        //   "sort": 1693667156355,
        //   type: '难度裁判',
        //   score: 5.0,
        //   subScore:0.5,
        //   createBy: '系统管理员',
        //   createTime: '2023-09-02 23:05:56',
        //   name: '难度一',
        //   "id": 169366715635524,
        //   status: '未打分'
        // },
        // {
        //   refereeId: '169364142917657',
        //   competitionId: '169364009900655',
        //   applyProjectId: '169364029354930',
        //   orderId: '169364041855915',
        //   idCard: '150422199803063328',
        //   "sort": 1693667156355,
        //   type: '难度裁判',
        //   score: 5.0,
        //   subScore:1.0,
        //   createBy: '系统管理员',
        //   createTime: '2023-09-02 23:05:56',
        //   name: '难度二',
        //   "id": 169366715635524,
        //   status: '未打分'
        // },
        // {
        //   refereeId: '169364142917229',
        //   competitionId: '169364009900655',
        //   applyProjectId: '169364029354930',
        //   orderId: '169364041855915',
        //   idCard: '150422199803063327',
        //   "sort": 1693667156353,
        //   type: '完成裁判',
        //   score: 5.0,
        //   createBy: '系统管理员',
        //   createTime: '2023-09-02 23:05:56',
        //   name: '李五',
        //   "id": 16936671563534,
        //   status: '未打分'
        // },
        // {
        //   refereeId: '169364142915455',
        //   competitionId: '169364009900655',
        //   applyProjectId: '169364029354930',
        //   orderId: '169364041855915',
        //   idCard: '150422199803063326',
        //   "sort": 1693667156340,
        //   type: '完成裁判',
        //   score: 5.0,
        //   createBy: '系统管理员',
        //   createTime: '2023-09-02 23:05:56',
        //   name: '李一同',
        //   "id": 169366715634045,
        //   status: '未打分'
        // },
        // {
        //   refereeId: '169364142916969',
        //   competitionId: '169364009900655',
        //   applyProjectId: '169364029354930',
        //   orderId: '169364041855915',
        //   idCard: '150422199803063325',
        //   "sort": 1693667156350,
        //   type: '完成裁判',
        //   score: 5.0,
        //   createBy: '系统管理员',
        //   createTime: '2023-09-02 23:05:56',
        //   name: '李向',
        //   "id": 169366715635012,
        //   status: '未打分'
        // },
        // {
        //   refereeId: '169364142917657',
        //   competitionId: '169364009900655',
        //   applyProjectId: '169364029354930',
        //   orderId: '169364041855915',
        //   idCard: '150422199803063328',
        //   "sort": 1693667156355,
        //   type: '完成裁判',
        //   score: 5.0,
        //   createBy: '系统管理员',
        //   createTime: '2023-09-02 23:05:56',
        //   name: '李六',
        //   "id": 169366715635524,
        //   status: '未打分'
        // },
        
        // // {
        // //   refereeId: '169364142917657',
        // //   competitionId: '169364009900655',
        // //   applyProjectId: '169364029354930',
        // //   orderId: '169364041855915',
        // //   idCard: '150422199803063328',
        // //   "sort": 1693667156355,
        // //   type: '完成裁判',
        // //   score: 5.0,
        // //   createBy: '系统管理员',
        // //   createTime: '2023-09-02 23:05:56',
        // //   name: '李六',
        // //   "id": 169366715635524,
        // //   status: '未打分'
        // // },
        // {
        //   refereeId: '169364142915151',
        //   competitionId: '169364009900655',
        //   applyProjectId: '169364029354930',
        //   orderId: '169364041855915',
        //   idCard: '150422199803063322',
        //   "sort": 1693667156338,
        //   type: '艺术裁判',
        //   score: 7.2,
        //   createBy: '系统管理员',
        //   createTime: '2023-09-02 23:05:56',
        //   name: '李二',
        //   "id": 169366715633845,
        //   status: '未打分'
        // },
        // {
        //   refereeId: '169364142915955',
        //   competitionId: '169364009900655',
        //   applyProjectId: '169364029354930',
        //   orderId: '169364041855915',
        //   idCard: '150422199803063321',
        //   "sort": 1693667156342,
        //   type: '艺术裁判',
        //   score: 8.0,
        //   createBy: '系统管理员',
        //   createTime: '2023-09-02 23:05:56',
        //   name: '李四',
        //   "id": 169366715634251,
        //   status: '未打分'
        // },
        // {
        //   refereeId: '169364142916244',
        //   competitionId: '169364009900655',
        //   applyProjectId: '169364029354930',
        //   orderId: '169364041855915',
        //   idCard: '150422199803063323',
        //   "sort": 1693667156345,
        //   type: '艺术裁判',
        //   score: 10.0,
        //   createBy: '系统管理员',
        //   createTime: '2023-09-02 23:05:56',
        //   name: '李一',
        //   "id": 169366715634569,
        //   status: '未打分'
        // },
        // // {
        // //   refereeId: '169364142916519',
        // //   competitionId: '169364009900655',
        // //   applyProjectId: '169364029354930',
        // //   orderId: '169364041855915',
        // //   idCard: '150422199803063324',
        // //   "sort": 1693667156348,
        // //   type: '艺术裁判',
        // //   score: 3.0,
        // //   createBy: '系统管理员',
        // //   createTime: '2023-09-02 23:05:56',
        // //   name: '李吧',
        // //   "id": 169366715634865,
        // //   status: '未打分'
        // // },
        // {
        //   refereeId: '169364142916519',
        //   competitionId: '169364009900655',
        //   applyProjectId: '169364029354930',
        //   orderId: '169364041855915',
        //   idCard: '150422199803063324',
        //   "sort": 1693667156348,
        //   type: '艺术裁判',
        //   score: 3.2,
        //   createBy: '系统管理员',
        //   createTime: '2023-09-02 23:05:56',
        //   name: '李吧',
        //   "id": 169366715634865,
        //   status: '未打分'
        // },
        // {
        //   refereeId: '16936414291796',
        //   competitionId: '169364009900655',
        //   applyProjectId: '169364029354930',
        //   orderId: '169364041855915',
        //   idCard: '150422199706032255',
        //   "sort": 1693667156335,
        //   type: '副裁判长',
        //   score: 0,
        //   createBy: '系统管理员',
        //   createTime: '2023-09-02 23:05:56',
        //   name: '李亏',
        //   "id": 169366715633538,
        //   status: '未打分'
        // },
        // {
        //   refereeId: '169364142918279',
        //   competitionId: '169364009900655',
        //   applyProjectId: '169364029354930',
        //   orderId: '169364041855915',
        //   idCard: '150422199803063328',
        //   "sort": 1693667156358,
        //   type: '裁判长',
        //   score: 0,
        //   createBy: '系统管理员',
        //   createTime: '2023-09-02 23:05:56',
        //   name: '张三',
        //   "id": 169366715635822,
        //   status: '未打分'
        // }
      ]
    }
  },
  computed:{
    ...mapState({
      referee:state => state.user.refereeInfo
    }),
  },
  watch: {
    scoreId(newVal,oldVal){
      this.setScoreData()
      this.setRefereeData()
    },
    fnName(newVal,oldVal){
     this.formula = newVal
    }
  },
  created() {
    this.getRefereeProject()
    this.getData();
    this.setTime();
  },
  beforeDestroy(){
    clearInterval(this.timer);// 清除定时器
    this.timer = null;
  },
  methods:{
    // 打分计算公式
    // 竞技健美操2.0
    competitive20 () {
      let arrArt = this.refereeList.filter(item => item.type == '艺术裁判')
      let arrArtAva = arrArt.map(item => item.score)
      let sumArt = 0
      arrArtAva.sort((a,b)=>a-b);
      arrArtAva.pop();
      arrArtAva.shift();
      for(var i=0;i<arrArtAva.length;i++){
        sumArt += arrArtAva[i];
      }
      sumArt = (sumArt / arrArtAva.length).toFixed(2)
      let arrFin = this.refereeList.filter(item => item.type == '完成裁判')
      let arrFinAva = arrFin.map(item => item.score)
      let sumFin = 0
      arrFinAva.sort((a,b)=>a-b);
      arrFinAva.pop();
      arrFinAva.shift();
      for(var i=0;i<arrFinAva.length;i++){
        sumFin += arrFinAva[i];
      }
      sumFin = (sumFin / arrFinAva.length).toFixed(2)
      let arrDif = this.refereeList.filter(item => item.type == '难度裁判')
      let arrDifAva = arrDif.map(item => item.score)
      let arrDifSub = arrDif.map(item => item.subScore)
      let sumDif = 0
      let sumSubDif = 0
      for(var i=0;i<arrDifAva.length;i++){
        sumDif += arrDifAva[i];
      }
      for(var i=0;i<arrDifSub.length;i++){
        sumSubDif += arrDifSub[i];
      }
      sumDif = ((sumDif/2/2)-(sumSubDif/2))
      this.averageScore = parseFloat(sumFin) + parseFloat(sumArt) + parseFloat(sumDif)
    },
    // 竞技健美操18
    competitive18 () {
      let arrArt = this.refereeList.filter(item => item.type == '艺术裁判')
      let arrArtAva = arrArt.map(item => item.score)
      let sumArt = 0
      arrArtAva.sort((a,b)=>a-b);
      arrArtAva.pop();
      arrArtAva.shift();
      for(var i=0;i<arrArtAva.length;i++){
        sumArt += arrArtAva[i];
      }
      sumArt = (sumArt / arrArtAva.length).toFixed(2)
      let arrFin = this.refereeList.filter(item => item.type == '完成裁判')
      let arrFinAva = arrFin.map(item => item.score)
      let sumFin = 0
      arrFinAva.sort((a,b)=>a-b);
      arrFinAva.pop();
      arrFinAva.shift();
      for(var i=0;i<arrFinAva.length;i++){
        sumFin += arrFinAva[i];
      }
      sumFin = (sumFin / arrFinAva.length).toFixed(2)
      let arrDif = this.refereeList.filter(item => item.type == '难度裁判')
      let arrDifAva = arrDif.map(item => item.score)
      let arrDifSub = arrDif.map(item => item.subScore)
      let sumDif = 0
      let sumSubDif = 0
      for(var i=0;i<arrDifAva.length;i++){
        sumDif += arrDifAva[i];
      }
      for(var i=0;i<arrDifSub.length;i++){
        sumSubDif += arrDifSub[i];
      }
      sumDif = ((sumDif/2/1.8)-(sumSubDif/2))
      this.averageScore = parseFloat(sumFin) + parseFloat(sumArt) + parseFloat(sumDif)
    },
    // 竞技健美操17
    competitive17 () {
      let arrArt = this.refereeList.filter(item => item.type == '艺术裁判')
      let arrArtAva = arrArt.map(item => item.score)
      let sumArt = 0
      arrArtAva.sort((a,b)=>a-b);
      arrArtAva.pop();
      arrArtAva.shift();
      for(var i=0;i<arrArtAva.length;i++){
        sumArt += arrArtAva[i];
      }
      sumArt = (sumArt / arrArtAva.length).toFixed(2)
      let arrFin = this.refereeList.filter(item => item.type == '完成裁判')
      let arrFinAva = arrFin.map(item => item.score)
      let sumFin = 0
      arrFinAva.sort((a,b)=>a-b);
      arrFinAva.pop();
      arrFinAva.shift();
      for(var i=0;i<arrFinAva.length;i++){
        sumFin += arrFinAva[i];
      }
      sumFin = (sumFin / arrFinAva.length).toFixed(2)
      let arrDif = this.refereeList.filter(item => item.type == '难度裁判')
      let arrDifAva = arrDif.map(item => item.score)
      let arrDifSub = arrDif.map(item => item.subScore)
      let sumDif = 0
      let sumSubDif = 0
      for(var i=0;i<arrDifAva.length;i++){
        sumDif += arrDifAva[i];
      }
      for(var i=0;i<arrDifSub.length;i++){
        sumSubDif += arrDifSub[i];
      }
      sumDif = ((sumDif/2/1.7)-(sumSubDif/2))
      this.averageScore = parseFloat(sumFin) + parseFloat(sumArt) + parseFloat(sumDif)
    },
    // 舞蹈啦啦操
    dance () {
      let refArr = this.refereeList.filter(item => item.type !== '裁判长' && item.type !== '副裁判长')
      let arrRefAva = refArr.map(item => item.score)
      let sumRef = 0
      arrRefAva.sort((a,b)=>a-b);
      arrRefAva.pop();
      arrRefAva.shift();
      for(var i=0;i<arrRefAva.length;i++){
        sumRef += arrRefAva[i];
      }
      this.averageScore = parseFloat(sumRef)
    },
    // 技巧啦啦操
    skill () {
      let refArr = this.refereeList.filter(item => item.type !== '裁判长' && item.type !== '副裁判长')
      let arrRefAva = refArr.map(item => item.score)
      let sumRef = 0
      arrRefAva.sort((a,b)=>a-b);
      arrRefAva.pop();
      arrRefAva.shift();
      for(var i=0;i<arrRefAva.length;i++){
        sumRef += arrRefAva[i];
      }
      this.averageScore = parseFloat(sumRef)
    },
    // 健身操舞
    fitness  () {
      console.log("🚀 ~ file: headreferee.vue:604 ~ fitness ~ fitness:", 'j健身操无')
      
      let arrArt = this.refereeList.filter(item => item.type == '艺术裁判')
      let arrArtAva = arrArt.map(item => item.score)
      let sumArt = 0
      arrArtAva.sort((a,b)=>a-b);
      arrArtAva.pop();
      arrArtAva.shift();
      for(var i=0;i<arrArtAva.length;i++){
        sumArt += arrArtAva[i];
      }
      sumArt = (sumArt / arrArtAva.length).toFixed(2)
      let arrFin = this.refereeList.filter(item => item.type == '完成裁判')
      let arrFinAva = arrFin.map(item => item.score)
      let sumFin = 0
      arrFinAva.sort((a,b)=>a-b);
      arrFinAva.pop();
      arrFinAva.shift();
      for(var i=0;i<arrFinAva.length;i++){
        sumFin += arrFinAva[i];
      }
      sumFin = (sumFin / arrFinAva.length).toFixed(2)
      this.averageScore = parseFloat(sumFin) + parseFloat(sumArt)
    },
    change(e) {
      if(e.type == '难度裁判') {
        this.inputBox = true
      } else {
        this.inputBox = false
      }
      this.dialogVisible = true
      this.input = e.score
      this.input2 = e.subScore
      this.normalscore = e
    },
    editNormalScore() {
      this.dialogVisible = false
      this.normalscore.score = this.input
      this.normalscore.subScore = this.input2
      let params = this.normalscore
      submitscore(params).then(res => {
        if(res.code == 200) {
          this.$message({
            type: 'success',
            message: '改分成功!'
          });
        } else {
          this.$message({
            type: 'danger',
            message: '改分失败'
          });       
        }
      })
    },
    agree(e) {
      this.$confirm('是否同意修改分数?', '提示', {
        confirmButtonText: '同意',
        cancelButtonText: '拒绝',
        type: 'warning'
      }).then(() => {
        const params = {
          applyProjectId:this.scoreData.id,
          refereeId:e.refereeId,
          result:'yes'
        }
        agreescore(params).then(res => {
          if(res.code == 200) {
            this.$message({
              type: 'success',
              message: '允许成功!'
            });
          } else {
            this.$message({
              type: 'danger',
              message: '允许成功'
            });       
          }
        })
      }).catch(() => {
        let params = {
          applyProjectId:this.scoreData.id,
          refereeId:e.refereeId,
          result:'no'
        }
        agreescore(params).then(res => {
          this.$message({
            type: 'info',
            message: '拒绝改分'
          });  
        })        
      });
    },
    computedAverage() {
      // this.competitive20()
      switch(this.formula) {
        case '竞技健美操2.0':
           this.competitive20()
        break;
        case '竞技健美操1.8':
           this.competitive18()
        break;
        case '竞技健美操1.7':
          this.competitive17()
        break;
        case '舞蹈啦啦操':
          this.dance()
        break;
        case '技巧啦啦操':
          this.skill()
        break;
        default:
        this.fitness()
        break;
      }
      // let arr = this.refereeList.map(item => item.score)
      // let sum = 0
      // arr.sort((a,b)=>a-b);
      // arr.pop();
      // arr.shift();
      // for(var i=0;i<arr.length;i++){
      //   sum += arr[i];
      // }
      // sum = (sum / arr.length).toFixed(2)
      // this.averageScore = sum
      // this.computedScore = sum
      // this.finalScore = sum
    },
    computedFinal(){
      if(this.addscore!==0) {
        let fs = parseFloat(this.averageScore) + this.addscore - this.sightScore
        this.computedScore  = fs.toFixed(2)
      } else if(this.reducescore!==0) {
        let fs = parseFloat(this.averageScore) - this.reducescore - this.sightScore
        this.computedScore  = fs.toFixed(2)
      } else {
        this.computedScore = parseFloat(this.averageScore) - this.sightScore
      }
    },
    submitFinalScore() {
      this.$confirm('此操作将提交打分, 是否继续?', '提示', {
        confirmButtonText: '提交',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        const params = {
          applyProjectId:this.scoreData.id,
          idCard:this.referee.idCard,
          name:this.referee.name,
          type:this.referee.type,
          score:this.computedScore,
          orderId:this.referee.orderId,
          addScore:this.addscore,
          sightScore:this.sightScore,
          reduceScore:this.reducescore,
          averageScore:this.averageScore
        }
        submitscore(params).then(res => {
          if(res.code == 200) {
            this.$message({
              type: 'success',
              message: '打分成功!'
            });
          } else {
            this.$message({
              type: 'danger',
              message: '打分失败'
            });       
          }
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '取消打分'
        });          
      });
    },
    setTime(){ 
      //每隔一分钟运行一次保存方法
      this.timer = setInterval(()=>{
        this.getData();
      },5000)
    },
    getData(){
      getNowData().then(res => {
        // console.log("🚀 ~ file: headreferee.vue:321 ~ getNowData ~ res:", res.data.applyProject.type)
        this.scoreId = res.data.applyProject.id
        if(res.data.formula) {
          this.fnName = res.data.formula
        } else {
          this.fnName = '健身操舞'
        }
      })
      getAllData().then(res => {
        this.refereeList = res.data.refereeScore.sort((a,b) => (a.type).localeCompare(b.type, 'zh-CN'))
        this.tableData = res.data.applyProjects
        this.positionIndex()
      })
    },
    setScoreData() {
      getNowData().then(res => {
        this.scoreData = res.data.applyProject
        // this.positionIndex()
      })
    },
    setRefereeData() {
      getAllData().then(res => {
        this.refereeList = res.data.refereeScore.sort((a,b) => (a.type).localeCompare(b.type, 'zh-CN'))
        this.tableData = res.data.applyProjects
        // this.positionIndex()
      })
    },
    getRefereeProject() {
      getAllData().then(res => {
        this.tableData = res.data.applyProjects
        this.refereeList = res.data.refereeScore.sort((a,b) => (a.type).localeCompare(b.type, 'zh-CN'))
        // this.positionIndex()
      })
    },
    positionIndex(e) {
      if (this.tableData && this.tableData.length) {
        for (var i = 0; i < this.tableData.length; i++) {
            if (this.tableData[i].status == '正在打分') {
                this.$refs['gameTable'].setCurrentRow(this.tableData[i]);
                var dom = this.$refs.gameTable.bodyWrapper;
                this.$nextTick(() => {
                  if(e>2) {
                    dom.scrollTo(0, 57 * (e - 2));
                  } else {
                    return
                  }
                });
                return;
            }
        }
        this.$message.error('未找到相关数据');
        // this.scanData = null;
        // this.$refs.scanDataRef.focus();
        return;
      }
    }
  }
}
</script>

<style>
.clearfix:before,
.clearfix:after {
  display: table;
  content: "";
}
.clearfix:after {
  clear: both
}
.el-rate {
  height: 50px;
}
.el-rate__icon {
  font-size: 50px;
  margin-right: 6px;
  color: #C0C4CC;
  transition: .3s;
}
.bottom {
  margin-top: 13px;
  line-height: 12px;
  text-align: center;
  padding: 14px 0;
  font-size: 16px;
  color: #ffffff;
  font-weight: bold;
}
.el-col-lg-24-5 {
  width: 20%;
}
.el-col-lg-24-15 {
  width: 60%;
}
.already {
  background-color: #409EFF;
}
.noready {
  background-color: #909399;
}
.headreferee {
  background-color: #67C23A;
}
.headreferee1 {
  background-color: #409EFF;
}
.el-table--striped .el-table__body tr.el-table__row--striped.current-row td, .el-table__body tr.current-row > td {
  color: #fff;
  background-color: #409EFF !important;
}
.submit-score {
  display: flex;
  flex-direction: row;
  /* justify-content:center;
  align-items: center; */
  height: 100%;
}
</style>